/* eslint-disable no-nested-ternary */
import { appHistory, isInIcestark } from '@ice/stark-app';
import { Redirect, useAuth } from 'ice';

const LoginWrapper = (WrappedComponent) => {
  const [auth] = useAuth();

  const LoginWrappedPage = (props) => {
    return (
      <>
        {auth.isLogin ? (
          <WrappedComponent {...props} />
        ) : isInIcestark() ? (
          appHistory.replace('/login')
        ) : (
          <Redirect to="/login" />
        )}
      </>
    );
  };

  return LoginWrappedPage;
};

export default LoginWrapper;
